import { createRouter, createWebHashHistory } from 'vue-router'

// 路由懒加载(按需导入)
const Login = () => import('@/views/login/index.vue')
const Layout = () => import('@/views/layout/index.vue')
const Home = () => import('@/views/home/index.vue')
const Test = () => import('@/views/test/index.vue')
const TopCategory = () => import('@/views/category')
const SubCategory = () => import('@/views/category/sub.vue')
const Goods = () => import('@/views/goods/index.vue')

const routes = [
  // 主页面路由配置
  {
    path: '/',
    component: Layout,
    children: [
      // 主页二级路由配置
      { path: '/', component: Home },
      { path: '/category/:id', component: TopCategory },
      { path: '/category/sub/:id', component: SubCategory },
      { path: '/product/:id', component: Goods }
    ]
  },
  // 登录页面路由配置
  { path: '/login', component: Login },
  { path: '/test', component: Test }
]

const router = createRouter({
  history: createWebHashHistory(),
  routes,
  // 路由跳转后直接回滚到顶部
  scrollBehavior () {
    return { left: 0, top: 0 }
  }

})

export default router
